﻿/* Copyright (c) 2011-2012, Zetatron Consulting
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name of Zetatron Consulting nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AionCxxLibrary.Packets;
using WorldServer.Models;
using WorldServer.Services;
using AionCxxLibrary.Enums;

namespace WorldServer.Packets.Server
{
    public class SPkt_CharacterLocation : AionServerPacket
    {
        public override void WritePacket()
        {
            Character c = ((WorldConnection)Connection).Character;
            WriteInt(c.Position.WorldID);
            WriteInt(c.Position.WorldID);
            WriteInt(0);
            WriteByte(0);
            WriteVector(c.Position.To4D());
            WriteInt(0);
            WriteByte(0);
        }
    }

    public class SPkt_LevelChannelInfo : AionServerPacket
    {
        public override void WritePacket()
        {
            WriteInt(0);
            WriteInt(2);
        }
    }

    public class SPkt_DespawnObject : AionServerPacket
    {
        int guid;
        byte time;
        public SPkt_DespawnObject(int objectGuid, byte animationTime)
        {
            guid = objectGuid;
            time = animationTime;
        }

        public override void WritePacket()
        {
            WriteInt(guid);
            WriteByte(time);
        }
    }

    public class SPkt_ObjectMove : AionServerPacket
    {
        int guid;
        byte[] data;
        public SPkt_ObjectMove(int guid, byte[] data)
        {
            this.guid = guid;
            this.data = data;
        }

        public override void WritePacket()
        {
            WriteInt(guid);
            WriteBytes(data);
        }

    }

    public class SPkt_NPC : AionServerPacket
    {
        NPC npc;
        public SPkt_NPC(NPC obj)
        {
            npc = obj;
        }

        public override void WritePacket()
        {
            WriteFloat(npc.Position.x);
            WriteFloat(npc.Position.y);
            WriteFloat(npc.Position.z);
            WriteInt(npc.GetGUID());
            WriteInt(npc.NpcID);
            WriteInt(npc.NpcID);

            WriteByte(0); // Attackable
            WriteShort(0x21); // NPC State
            WriteByte(npc.Position.h);
            WriteInt(npc.Template.NameID);

            WriteInt(0); // NPC Title ID

            WriteBytes(new byte[7]);

            WriteInt(npc.Creator == null ? 0 : npc.Creator.GetGUID());
            WriteString(npc.Creator != null && npc.Creator is Character ? (npc.Creator as Character).Template.Name : "");

            WriteByte(100); // % HP
            WriteInt(5000); // Max HP

            WriteByte(254); // NPC Level

            WriteUnsignedShort(0); // Equipment Mask (TODO implement eq)

            WriteInt(1051931443);
            WriteFloat(1f); // NPC Height
            WriteFloat(6); // NPC Speed

            WriteShort(2000);
            WriteShort(2000);

            WriteByte(0); // Is Servant

            WriteFloat(npc.Position.x);
            WriteFloat(npc.Position.y);
            WriteFloat(npc.Position.z);
            WriteByte(0);

            WriteUnsignedShort(0); // StaticID

            WriteBytes(new byte[8]);
            WriteByte(0); // Visual State

            WriteShort(1); // NPC Type
            WriteByte(0);
            WriteInt(npc.Target != null ? npc.Target.GetGUID() : 0);
        }
    }

}
